home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFE_SIM / VERSION_ / DOCELLUL.C < prev    next >
Text File  |  1992-03-12  |  3KB  |  143 lines

  1. /* Cell Proj 1.0 */
  2.  
  3. #include "MacProto.h"
  4. #include "Cell_Proto.h"
  5. #include "Cell_Definitions.h"
  6. #include "Cell_Variables.h"
  7.  
  8. DoCellularAutomata()
  9. {    
  10.     int        a, b;
  11.     int        count;
  12.     int        lifeSum[ NUMBER_OF_CELLS ];
  13.     int        itemType;
  14.     Rect    itemRect;
  15.     Handle    itemHandle;
  16.     Str255    textOverPop, textOverExp;
  17.     
  18.     GetDItem( gCellInfoDialog, OVER_POP_ITEM, &itemType, &itemHandle,
  19.                                                     &itemRect );
  20.     GetIText( itemHandle, &textOverPop );
  21.     StringToNum( textOverPop, &gOverPop );
  22.     
  23.     GetDItem( gCellInfoDialog, OVER_EXP_ITEM, &itemType, &itemHandle,
  24.                                                     &itemRect );
  25.     GetIText( itemHandle, &textOverExp );
  26.     StringToNum( textOverExp, &gOverExp );
  27.  
  28.     for ( count = 0; count < NUMBER_OF_CELLS; count++ )    /* add up pnts around the pixel */
  29.     {
  30.         lifeSum[ count ] = 0;
  31.         
  32.         if ( count - 100 < 0 )
  33.             lifeSum[ count ] += gCellStatus[ count + 900 ];
  34.         else
  35.             lifeSum[ count ] += gCellStatus[ count - 100 ];    /* pnt directly above it */
  36.  
  37.         if ( count - 99 < 0 )
  38.             lifeSum[ count ] += gCellStatus[ count + 901 ];
  39.         else
  40.             lifeSum[ count ] += gCellStatus[ count - 99 ];    /* pnt directly above it */
  41.  
  42.         if ( count - 101 < 0 )
  43.             lifeSum[ count ] += gCellStatus[ count + 899 ];
  44.         else
  45.             lifeSum[ count ] += gCellStatus[ count - 101 ];    /* pnt directly above it */
  46.  
  47.  
  48.  
  49.         if ( count + 99 > 9999 )
  50.             lifeSum[ count ] += gCellStatus[ count - 901 ];
  51.         else
  52.             lifeSum[ count ] += gCellStatus[ count + 99 ];    /* pnt directly above it */
  53.  
  54.         if ( count + 101 > 9999 )
  55.             lifeSum[ count ] += gCellStatus[ count - 899 ];
  56.         else
  57.             lifeSum[ count ] += gCellStatus[ count + 101 ];    /* pnt directly above it */
  58.  
  59.         if ( count + 100 > 9999 )
  60.             lifeSum[ count ] += gCellStatus[ count - 900 ];
  61.         else
  62.             lifeSum[ count ] += gCellStatus[ count + 100 ];    /* pnt directly above it */
  63.  
  64.  
  65.  
  66.         if ( count == 0 )
  67.             lifeSum[ count ] += gCellStatus[ 9999 ];
  68.         else
  69.             lifeSum[ count ] += gCellStatus[ count - 1 ];    /* pnt directly above it */
  70.  
  71.         if ( count == 9999 )
  72.             lifeSum[ count ] += gCellStatus[ 0 ];
  73.         else
  74.             lifeSum[ count ] += gCellStatus[ count + 1 ];    /* pnt directly above it */
  75.         
  76.         GraphResults( count, lifeSum );
  77.     }
  78.     MoveRsltsTo_gCellStatus( lifeSum );
  79. }
  80.  
  81. GraphResults( count, lifeSum )
  82. int            count;
  83. int            *lifeSum;
  84. {    
  85.     if ( lifeSum[ count ] <= gOverExp )
  86.     {
  87.         GraphDead( count );
  88.         lifeSum[ count ] = 0;
  89.     }
  90.     if ( lifeSum[ count ] > gOverExp && lifeSum[ count ] < gOverPop )
  91.     {
  92.         GraphAlive( count );
  93.         lifeSum[ count ] = 1;
  94.     }
  95.     if ( lifeSum[ count ] >= gOverPop )
  96.     {
  97.         GraphDead( count );
  98.         lifeSum[ count ] = 0;
  99.     }
  100. }
  101.  
  102. GraphDead( count )
  103. int        count;
  104. {
  105.     int        x, y;
  106.     
  107.     x = count / 100;
  108.     y = count - ( 100 * x );
  109.     
  110.     SetPort ( gCellWindow );
  111.     PenNormal ();
  112.     ForeColor ( whiteColor );
  113.     
  114.     MoveTo ( x, y );
  115.     LineTo ( x, y );
  116. }
  117.  
  118. GraphAlive( count )
  119. int        count;
  120. {
  121.     int        x, y;
  122.     
  123.     x = count / 100;
  124.     y = count - ( 100 * x );
  125.     
  126.     SetPort ( gCellWindow );
  127.     PenNormal ();
  128.     ForeColor ( blackColor );
  129.     
  130.     MoveTo ( x, y );
  131.     LineTo ( x, y );
  132. }
  133.  
  134. MoveRsltsTo_gCellStatus( lifeSum )
  135. int        lifeSum[];
  136. {
  137.     int        count;
  138.     
  139.     for ( count = 0; count < NUMBER_OF_CELLS; count++ )    /* add up pnts around the pixel */
  140.     {
  141.         gCellStatus[ count ] = lifeSum [ count ];
  142.     }
  143. }